package com.ruoyi.web.controller.enterprise;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EnterpriseRelationship;
import com.ruoyi.system.service.IEnterpriseRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业关系Controller
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/enterprise/relationship")
public class EnterpriseRelationshipController extends BaseController
{
    @Autowired
    private IEnterpriseRelationshipService enterpriseRelationshipService;

    /**
     * 查询企业关系列表
     */
    // @PreAuthorize("@ss.hasPermi('enterprise:relationship:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(EnterpriseRelationship enterpriseRelationship)
    {
        startPage();
        List<EnterpriseRelationship> list = enterpriseRelationshipService.selectEnterpriseRelationshipList(enterpriseRelationship);
        return getDataTable(list);
    }

    /**
     * 导出企业关系列表
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:relationship:export')")
    @Log(title = "企业关系", businessType = BusinessType.EXPORT)
    @Anonymous
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnterpriseRelationship enterpriseRelationship)
    {
        List<EnterpriseRelationship> list = enterpriseRelationshipService.selectEnterpriseRelationshipList(enterpriseRelationship);
        ExcelUtil<EnterpriseRelationship> util = new ExcelUtil<EnterpriseRelationship>(EnterpriseRelationship.class);
        util.exportExcel(response, list, "企业关系数据");
    }

    /**
     * 获取企业关系详细信息
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:relationship:query')")
    @Anonymous
    @GetMapping(value = "/{cooperationId}")
    public AjaxResult getInfo(@PathVariable("cooperationId") Integer cooperationId)
    {
        return success(enterpriseRelationshipService.selectEnterpriseRelationshipByCooperationId(cooperationId));
    }

    /**
     * 新增企业关系
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:relationship:add')")
    @Log(title = "企业关系", businessType = BusinessType.INSERT)
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody EnterpriseRelationship enterpriseRelationship)
    {
        return toAjax(enterpriseRelationshipService.insertEnterpriseRelationship(enterpriseRelationship));
    }

    /**
     * 修改企业关系
     */
    // @PreAuthorize("@ss.hasPermi('enterprise:relationship:edit')")
    @Log(title = "企业关系", businessType = BusinessType.UPDATE)
    @Anonymous
    @PutMapping
    public AjaxResult edit(@RequestBody EnterpriseRelationship enterpriseRelationship)
    {
        return toAjax(enterpriseRelationshipService.updateEnterpriseRelationship(enterpriseRelationship));
    }

    /**
     * 删除企业关系
     */
    //@PreAuthorize("@ss.hasPermi('enterprise:relationship:remove')")
    @Log(title = "企业关系", businessType = BusinessType.DELETE)
    @Anonymous
	@DeleteMapping("/{cooperationIds}")
    public AjaxResult remove(@PathVariable Integer[] cooperationIds)
    {
        return toAjax(enterpriseRelationshipService.deleteEnterpriseRelationshipByCooperationIds(cooperationIds));
    }
}
